home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_8.zip
/
DOC.ZIP
/
FIBB.ADA
next >
Wrap
Text File
|
1993-08-17
|
2KB
|
60 lines
--
-- Program : Fibb.ada
-- Purpose : This program calculates a fibbinochi number. This number
-- is calculated by summing all the numbers up to and including
-- that number. For example, 4 would be
--
-- 1 + 2 + 3 + 4 = 10
--
-- It is similar to a factorial, but the growth of the number
-- is much slower, and so we can use it with a much larger
-- level of recursion.
--
-- To use with GWUMON : To use this program with GWUMON, from the command
-- line type:
-- adacomp -a -b -mfibbinochi fibb.ada
-- gwumon -mfibbinochi
--
-- Take the default options on the first screen (speed = 6, exceptions = yes,
-- and tasks = no) by hitting the "Esc" key. Change from a Small
-- Window to a Large Window on the second screen.
--
-- The purpose of this program is to show a large amount of recursion.
-- Therefore, when prompted for the number to be calculated, choose 13.
-- This will cause the program to recursively call Fibb_Calc 13 times.
--
-- Notice that each time Fibb_Calc is called, a new window is opened until
-- a total of 12 windows are opened. At that point, no new windows are
-- created, but notice that the highest level window "Scrolls" off to the
-- upper right and is no longer visable.
--
-- When the program has gotten to the final window, notice how it begins
-- to scrool the windows back on to the screen as the call stack unwinds.
-- When all the programs on the stack are back on the screen, the stack
-- continues to unwind, until there is only a single procedure left on
-- the screen. This shows the call stack, and the recursion of the program.
--
WITH Text_IO;
PACKAGE My_Int_IO IS
NEW Text_IO.Integer_IO (Num => Integer);
WITH Text_IO; USE Text_IO;
WITH My_Int_IO; USE My_Int_IO;
PROCEDURE Fibbinochi IS
Temp : Integer;
FUNCTION Fibb_Calc( Current_Num: IN Integer ) RETURN Integer is
BEGIN
IF Current_Num = 0
THEN
RETURN 0;
END IF;
RETURN Current_Num + Fibb_Calc( Current_Num - 1 );
END Fibb_Calc;
BEGIN
PUT_LINE( "Enter the Fibbinochi number to be calculated" );
GET( Temp );
Temp := Fibb_Calc( Temp );
My_Int_IO.PUT( Item => Temp );
END Fibbinochi;